#define _GNU_SOURCE
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>

// 分线程函数
void *first_thread(void *arg)
{
    printf("first线程(%d)开始执行 \n", gettid());
    return NULL;
}

void *second_thread(void *arg)
{
    printf("second线程(%d)开始执行 \n", gettid());
}

// 主线程函数
int main(int argc, char const *argv[])
{
    printf("main线程(%d)开始执行 \n", gettid());

    // 创建2个分线程
    pthread_t first_pt, second_pt;
    pthread_create(&first_pt, NULL, first_thread, NULL);
    pthread_create(&second_pt, NULL, second_thread, NULL);

    printf("main线程(%d)继续执行 first_pt=%ld, second_pt=%ld \n", 
        gettid(), first_pt, second_pt);

    // 等待分线程执行完毕
    pthread_join(first_pt, NULL);
    pthread_join(second_pt, NULL);

    printf("main线程(%d)结束 \n", gettid());

    return 0;
}
